package 位运算;

public class 位1的个数1 {
    //https://leetcode.cn/problems/number-of-1-bits/description/
    public int hammingWeight(int n) {
        int sum = 0;
        while (n != 0) {
            n &= (n - 1);
            sum++;
        }
        return sum;
    }
}
